import sys
import os
from fastapi import APIRouter, HTTPException

# 添加项目根目录到Python路径
backend_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, backend_path)

# 修复导入路径
from api import stats_api

router = APIRouter()

@router.get("/fault-counts")
async def get_fault_counts():
    """获取故障数量统计"""
    try:
        return stats_api.get_fault_counts()
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@router.get("/manufacturer-stats")
async def get_manufacturer_stats():
    """获取厂家故障统计"""
    try:
        return stats_api.get_manufacturer_stats()
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@router.get("/dashboard-data")
async def get_dashboard_data():
    """获取仪表盘数据"""
    try:
        return stats_api.get_dashboard_data()
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))